package com.wyh.mybatis.mapper;

import com.wyh.mybatis.medol.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2025-07-07
 * Time: 16:34
 */

@Mapper
public interface UserInfoMapper {
//    @Select("select * from user_info")
//    @Select("SELECT delete_flag AS deleteFlag, create_time AS createTime, update_time AS updateTime FROM user_info")
//    @Results(id = "BaseMap", value = {
//            @Result(column = "delete_flag", property = "deleteFlag"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

//    @ResultMap(value = "BaseMap")
    @Select("SELECT * from user_info where id = #{id}")
    UserInfo selectById(Integer num);

    @Select("select * from user_info where id = #{aa} and username = #{name}")
    UserInfo selectByIdAndName(@Param("aa") int id, String name);

    @Insert("insert into user_info (username,`password`,age) VALUES (#{username},#{password},#{age})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Integer insert(UserInfo userInfo);

    @Select("SELECT * FROM user_info WHERE username = ${username}")
    UserInfo selectAll2(String username);

    @Select("SELECT * FROM user_info ORDER BY id ${od}")
    List<UserInfo> selectByOrder(String od);

    @Select("SELECT * FROM user_info WHERE age LIKE '%${age}%'")
    List<UserInfo> selectByLike(Integer age);

    @Select("SELECT * FROM user_info WHERE username = #{username} AND `password` = #{password}")
    UserInfo selectByNameAndPassword(String username, String password);
}
